<template>
  <div class="app-container">

    用户列表

    <br>
    <br>
    <!--    查询条件  -->
    <el-form :inline="true" class="demo-form-inline">

      <el-form-item label="基础信息" >

        <el-form-item>
          <el-input v-model="userQuery.name" placeholder="姓名"/>
        </el-form-item>
        <el-form-item>
          <el-input v-model="userQuery.email" placeholder="邮箱"/>
        </el-form-item>


        <el-form-item label="高级信息" >


          <el-form-item>
            <el-input v-model="userQuery.phone" placeholder="手机号"/>
          </el-form-item>

          <el-form-item>
            <el-input v-model="userQuery.ssn" placeholder="身份证"/>
          </el-form-item>


        </el-form-item>


        <el-button type="primary" icon="el-icon-search" @click="getList()">查 询</el-button>

        <el-button type="default" @click="resetData()">清空</el-button>
      </el-form-item>
    </el-form>

    <!-- 表格 -->
    <el-table
      :data="list"
      border
      fit
      highlight-current-row>

      <el-table-column
        label="序号"
        width="70"
        align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>

      </el-table-column>

      <el-table-column  label="头像" width="80">

        <template slot-scope="scope">
          <img :src="scope.row.avatar" style="width: 100%;height: 100%">
        </template>

      </el-table-column>

      <el-table-column prop="name" label="姓名" width="80"/>

      <el-table-column prop="gender" label="性别" width="80"/>

      <el-table-column prop="address" label="住址" width="180"/>

      <el-table-column prop="email" label="邮箱" width="180"/>

      <el-table-column prop="ssn" label="身份证"  width="170"/>

      <el-table-column prop="username" label="用户名" width="120"/>

      <el-table-column prop="phone" label="手机号" width="120"/>

      <el-table-column prop="password" label="密码" width="120"/>


      <el-table-column prop="gmtCreate" label="创建时间" width="100"/>

      <el-table-column prop="gmtModified" label="修改时间" width="100"/>


      <el-table-column label="操作" width="100" align="center">

        <template slot-scope="scope">
          <router-link :to="'/user/userAction/userEdit/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit" @click="updatePlane()">修改</el-button>
          </router-link>

          <el-button
            type="danger"
            size="mini"
            icon="el-icon-delete"
            @click="removeDataById(scope.row.id)">删除
          </el-button>
        </template>

      </el-table-column>

    </el-table>

    <!-- 分页 -->
    <el-pagination
      :current-page="page"
      :page-size="limit"
      :total="total"

      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getList"
    />
  </div>

</template>

<script>
import UserInfo from '../../../api/pc/user/infoList'

export default {
  name: 'list',
  data() {
    // 定义变量和初始值
    return {
      list: null, // 查询之后接口返回集合
      avatar:'',
      page: 1, // 当前页
      limit: 6, // 每页显示数
      total: 0, // 总记录数
      userQuery: {}, // 条件封装对象

    }
  },
  created() {
    this.getList()
  },
  methods: {

    /**
     * 进入页面打开 查询出所有用户
     * @param page
     */
    getList(page = 1) {
      this.page = page
      UserInfo.getUserListPage(this.page, this.limit, this.userQuery)
        .then(response => {
          this.list = response.data.rows
          this.total = response.data.total
          console.log(this.list[0].avatar)

        })
    },

    /**
     * 清除查询
     *
     */
    resetData() {
      this.userQuery = {}
      this.getList()
    },

    /**
     * 根据id删除用户
     * @param id
     */
    removeDataById(id) {
      this.$confirm('此操作将永久删除讲用户记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        UserInfo
          .deleteUserId(id)
          .then(response => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.getList()
          })
      })
    },

    /**
     * 跳转路由
     */
    updatePlane() {
      this.$router.push({ path: '/user/table/user' })

    }

  }
}
</script>


<style scoped>

</style>
